package com.yztc.youbadbad.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yztc.youbadbad.R;
import com.yztc.youbadbad.bean.homepage.ZhuanchangBean;
import com.yztc.youbadbad.helper.RecyclerViewAdapterHelper;
import com.yztc.youbadbad.helper.SpacesItemDecoration;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 首页 推荐
 */

public class TuijianHomepageRecyclerAdapter extends RecyclerViewAdapterHelper<ZhuanchangBean> {
    private boolean flag = true;
    private ProdectRecyclerAdapter.IProdectClickListener iProdectClickListener;//回调接口

    public TuijianHomepageRecyclerAdapter(Context context, List<ZhuanchangBean> list
    ,ProdectRecyclerAdapter.IProdectClickListener iProdectClickListener) {
        super(context, list);
        this.iProdectClickListener = iProdectClickListener;

    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_recycler_tuijian_type2, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ViewHolder) {
            ViewHolder holder2 = (ViewHolder) holder;
            ZhuanchangBean zhuanchang = (ZhuanchangBean) mList.get(position);//专场
            if (flag){
                ((ViewHolder) holder).titleRl.setVisibility(View.VISIBLE);
                flag = false;
            }else {
                ((ViewHolder) holder).titleRl.setVisibility(View.GONE);
            }
            holder2.titleFirTv.setText(zhuanchang.getTitle_fir());
            holder2.titleSecTv.setText(zhuanchang.getTitle_sec());

            Glide.with(mContext).load(zhuanchang.getEvent_img()).into(holder2.eventImgIv);

            //商品列表
            LinearLayoutManager manager10 = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL,false);
            ProdectRecyclerAdapter adapter10 = new ProdectRecyclerAdapter(mContext, zhuanchang.getEvent_product()
                                                        ,iProdectClickListener, position);
            holder2.eventProductRv.addItemDecoration(new SpacesItemDecoration(10));
            holder2.eventProductRv.setAdapter(adapter10);
            holder2.eventProductRv.setLayoutManager(manager10);
        }
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.title_rl)
        RelativeLayout titleRl;
        @BindView(R.id.event_img_iv)
        ImageView eventImgIv;
        @BindView(R.id.title_fir_tv)
        TextView titleFirTv;
        @BindView(R.id.title_sec_tv)
        TextView titleSecTv;
        @BindView(R.id.event_product_rv)
        RecyclerView eventProductRv;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
        //eventProductRv子布局 TODO

    }
}
